import Vue from 'vue';
import type {
  getChainConnListParam,
  operateChainConnParam,
  operateTestCaseParam,
  operateTestPlanParam,
} from './requestParam';

const jenkinsUrl = 'https://jenkins.chainmaker.org.cn/';
enum API {
  // 用户相关接口
  userLogin = '/api/user/login',
  getUserInfo = '/api/user/get_current_user_info',
  getUserList = '/api/user/query/user_list',
  userRegister = '/api/user/register',

  // 链操作相关接口
  getChainConnList = '/api/query/chains_conn_list',
  getChainConnInfo = '/api/query/chains_conn_info',
  operateChainConn = '/api/operate/chain_conn',
  upload = '/api/crypto/upload',

  // 测试用例相关接口
  getTestCaseList = '/api/query/testcase_list',
  getTestCaseInfo = '/api/query/testcase_info',
  operateTestCase = '/api/operate/testcase',

  // 测试计划相关接口
  getTestPlanList = '/api/query/testplan_list',
  getTestPlanInfo = '/api/query/testplan_info',
  operateTestPlan = '/api/operate/test_plan',
  // 其他接口
  getTags = '/api/query/tags',
  getSprints = '/api/query/sprints',

  // jenkins接口
  getJobs = '/api/json',

  // 性能测试接口
  getSceneList = '/api/performance/query/scene_list',
  // 保存链配置
  createChainConfig = '/api/performance/chain/config/create',
  // 更新链配置
  updateChainConfig = '/api/performance/chain/config/update',
  // 保存场景
  createSceneConfig = '/api/performance/scenario/create',


}

export function getSceneList(): string {
  return API.getSceneList;
}
export function login(): string {
  return API.userLogin;
}
export function getRemoteUserInfoAPI(): string {
  return API.getUserInfo;
}
export function getUserInfo(): string {
  // return Vue.prototype.$request.get(API.getUserInfo)
  return API.getUserInfo;
}

export function getUserList(): string {
  return API.getUserList;
}

export function userRegister(): string {
  return this.$request.get(API.userRegister);
}

export function getChainConnList(): string {
  return API.getChainConnList;
}

// export function getChainConnList(param?: getChainConnListParam):string {
//   if (param === undefined){
//     return Vue.prototype.$request.get(API.getChainConnList)
//   }
//   return Vue.prototype.$request.get(param)
//   // `${API.getChainConnList}?chain_name=${param.chain_name === undefined ? '' : param.chain_name}&con_state=${param.con_state === undefined ? undefined : param.con_state}&create_user=${param.create_user === undefined ? '' : param.create_user}`);

// }

// export function getChainConnInfo(id: string):string  {
//   return Vue.prototype.$request.get(`${API.getChainConnInfo}?id=${id}`);
// }

// export function operateChainConn(param: operateChainConnParam):string  {
//   return Vue.prototype.$request.post(API.operateChainConn, param);
// }
export function getChainConnInfo(): string {
  return API.getChainConnInfo;
}
export function operateChainConn(): string {
  return API.operateChainConn;
}

export function upload(): string {
  return API.upload;
}

export function getTestCaseList(): string {
  return API.getTestCaseList;
}

// export function getTestCaseList(param?: string):string {
//   if (param === undefined){
//     return Vue.prototype.$request.get(API.getTestCaseList)
//   }
//   return Vue.prototype.$request.get(param)
// }

export function getTestCaseInfo(): string {
  return API.getTestCaseInfo;
}

export function operateTestCase(): string {
  return API.operateTestCase;
}

export function operateTestPlan(): string {
  return API.operateTestPlan;
}

export function getTags(param?: string): string {
  if (param === undefined) {
    return Vue.prototype.$request.get(API.getTags);
  }
  return Vue.prototype.$request.get(param);
}

export function getSprints(param?: string): string {
  if (param === undefined) {
    return Vue.prototype.$request.get(API.getSprints);
  }
  return Vue.prototype.$request.get(param);
}

export function getJobs(): string {
  return `${jenkinsUrl}${API.getJobs}?pretty=true`;
}
// 保存链配置
export function createChainConfig(): string {
  return API.createChainConfig;
}


// 修改链配置
export function updateChainConfig(chain_type_id): string {
  return `/api/performance/chain/config/update?chain_type_id=${chain_type_id}`;
}

// 保存场景
export function createSceneConfig(): string {
  return API.createSceneConfig;
}

// 修改链配置
export function updateSceneConfig(scenario_id): string {
  return `/api/performance/scenario/update?scenario_id=${scenario_id}`;
}
